package com.lpy.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Aspect
public class RealizeTimeRecord {
    @Around("@annotation(com.lpy.aop.aspect.TimeRecord)")
    public Object timeRecord(ProceedingJoinPoint joinPoint) {
        long start = System.currentTimeMillis();

        Object result = null;
        try {
            result = joinPoint.proceed();
        }catch (Throwable e) {
            log.error(joinPoint.toString() + "发生异常: " + e);
        }

        log.info(joinPoint.toShortString() + "耗时: " + (System.currentTimeMillis() - start) + "ms");

        return result;
    }
}
